Skip to content

Msgctxt without project name #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

skyflyer
Copy link
Contributor

This change adds two unit tests that remove the project name from the and actually removes the project name from the generated context only for Razor metadata.

I created a sample project that this can be tested on: https://github.com/skyflyer/DotnetPoLocalizationDemo

The sample projects includes localization in .cshtml as well as localization in .cs (HomeController), which must preserve the project name (as it is part of the fully qualified class name).

@hishamco
Copy link
Member

hishamco commented Aug 10, 2025

Make sure your demo contains more than one module that contains at least one shared localization string, then check the generated output

@skyflyer
Copy link
Contributor Author

What do you mean by module? Like another project?

@hishamco
Copy link
Member

Exactly, because in Orchard Core, we have a lot of modules and some themes. So, one localization string could be used in many projects that's why the context is handy

@skyflyer
Copy link
Contributor Author

The solution now contains a solution with a Web (MVC) and a Razor Class Library (RCL) which is shared.

Food for thought: generate translation template looks like this:

#: PoLocalizationDemo.Lib/Views/Demo/Index.cshtml:6
#. <p>Localized string: @T["Welcome"]</p>
msgctxt "Views.Demo.Index"
msgid "Welcome"
msgstr ""

#: PoLocalizationDemo.Web/Controllers/HomeController.cs:32
#. ViewData["Message"] = T["Welcome from controller"];
msgctxt "PoLocalizationDemo.Web.Controllers.HomeController"
msgid "Welcome from controller"
msgstr ""

#: PoLocalizationDemo.Web/Views/Home/Index.cshtml:8
#. <h1 class="display-4">@T["Welcome"]</h1>
msgctxt "Views.Home.Index"
msgid "Welcome"
msgstr ""

As you can see, the library name is stripped from the views... but this leads me to wonder what would happen if two distinct razor class libraries would have the same view in the same directory and file name? E.g. Views.Home.Index

But, if the msgctxt is prefixed with the project name, the translation is not found by the Orchard localiation infrastructure, which generates the context based on the filename without the project name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants